package nkw;

import static org.junit.Assert.assertEquals;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Verifies that CompetitiveRobot always beats SittingDuck.
 * 
 * @author Noah Woodden
 */
public class TestVersusSittingDuck extends RobotTestBed {

  /**
   * Specifies that SittingDuck and CompetitiveRobot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,nkw.CompetitiveRobot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that CompetitiveRobot has won every round against SittingDuck.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is CompetitiveRobot (not strictly necessary, but illustrative).
    BattleResults botResults = battleResults[1];
    String robotName = botResults.getTeamLeaderName();
    assertEquals("Check that results[1] is CompetitiveRobot", robotName, "nkw.CompetitiveRobot*");

    // Check to make sure CompetitiveRobot won every round.
    assertEquals("Check CompetitiveRobot winner of all rounds", botResults.getFirsts(),
        getNumRounds());
  }

  /**
   * Returns true if the battle should be deterministic and thus robots will always start in the
   * same position each time.
   * 
   * Override to return false to support random initialization.
   * 
   * @return True if the battle will be deterministic.
   */
  @Override
  public boolean isDeterministic() {
    return false;
  }
}
